home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Tricks of the Mac Game Programming Gurus
/
TricksOfTheMacGameProgrammingGurus.iso
/
More Source
/
C⁄C++
/
PixelPlotTest
/
PixelPlotTest.p
< prev
next >
Wrap
Text File
|
1994-12-03
|
4KB
|
132 lines
program PixelPlotTest;
const
kSizeH = 300;
kSizeV = 40;
var
w: WindowPtr;
c, saveColor: RGBColor;
startTime, endTime: LongInt;
h, v, i: Integer;
r: Rect;
rowBytes: Longint;
pixAddr: Ptr;
baseAddr: Longint;
rowStartTable: array[0..kSizeV] of Longint;
mmuMode: SignedByte;
begin
SetRect(r, 100, 100, 400, 301);
w := NewCWindow(nil, r, 'Pixel Plotting Speed Test', true, 2, WindowPtr(-1), false, 0);
SetPort(w);
GetForeColor(saveColor);
c.red := $ffff;
c.green := 0;
c.blue := $ffff;
startTime := TickCount;
for h := 0 to kSizeH do
for v := 0 to kSizeV do
SetCPixel(h, v, c);
endTime := TickCount;
MoveTo(10, kSizeV + 20);
DrawString(stringof('SetCPixel test: ', (endTime - startTime) : 1, ' ticks.'));
c.red := $ffff;
c.green := $ffff;
c.blue := 0;
RGBForeColor(c);
startTime := TickCount;
for h := 0 to kSizeH do
for v := 0 to kSizeV do
begin
RGBForeColor(c);
MoveTo(h, v);
Line(0, 0);
end;
endTime := TickCount;
RGBForeColor(saveColor);
MoveTo(10, kSizeV + 40);
DrawString(stringof('MoveTo/LineTo test: ', (endTime - startTime) : 1, ' ticks.'));
c.red := 0;
c.green := $ffff;
c.blue := $ffff;
RGBForeColor(c);
startTime := TickCount;
for h := 0 to kSizeH do
for v := 0 to kSizeV do
begin
RGBForeColor(c);
SetRect(r, h, v, h + 1, v + 1);
PaintRect(r);
end;
endTime := TickCount;
RGBForeColor(saveColor);
MoveTo(10, kSizeV + 60);
DrawString(stringof('SetRect/PaintRect test: ', (endTime - startTime) : 1, ' ticks.'));
if GetMainDevice^^.gdPMap^^.pixelSize <> 8 then
begin
MoveTo(10, kSizeV + 80);
DrawString('Direct plotting is only supported in 256 colors/grays.');
end
else
begin
mmuMode := true32b;
{CWindowPtr(w)^.portPixMap^^.bounds.top;}
{CWindowPtr(w)^.portPixMap^^.bounds.left;}
rowBytes := BitAnd(GetMainDevice^^.gdPMap^^.rowBytes, $3fff);
SetRect(r, 0, 0, kSizeH, kSizeV);
ShieldCursor(r, CWindowPtr(w)^.portPixMap^^.bounds.topLeft);
baseAddr := Longint(GetMainDevice^^.gdPMap^^.baseAddr);
startTime := TickCount;
SwapMMUMode(mmuMode);
for i := 1 to 10 do
for h := 0 to kSizeH do
for v := 0 to kSizeV do
begin
pixAddr := Ptr(baseAddr + rowBytes * (v + 100) + h + 100);
pixAddr^ := $70 + i; {Some pixel value. We can get this through the color table.}
end;
SwapMMUMode(mmuMode);
endTime := TickCount;
ShowCursor;
MoveTo(10, kSizeV + 80);
DrawString(stringof('Direct plotting test: ', (endTime - startTime) : 1, ' ticks/10 times.'));
{Optimize by precalculating as much as possible:}
for v := 0 to kSizeV do
rowStartTable[v] := baseAddr + rowBytes * (v + 100) + 100;
ShieldCursor(r, CWindowPtr(w)^.portPixMap^^.bounds.topLeft); {Protect us from damaging the cursor}
startTime := TickCount;
SwapMMUMode(mmuMode); {We must be in 32-bit mode}
for i := 1 to 10 do
for h := 0 to kSizeH do
for v := 0 to kSizeV do
begin
pixAddr := Ptr(rowStartTable[v] + h);
pixAddr^ := $60 + i; {Some pixel value. We can get this through the color table.}
end;
SwapMMUMode(mmuMode); {Back to previous addressing mode}
endTime := TickCount;
ShowCursor; {Balances ShieldCursor}
MoveTo(10, kSizeV + 100);
DrawString(stringof('Opt. direct plotting test: ', (endTime - startTime) : 1, ' ticks/10 times.'));
end;
MoveTo(10, kSizeV + 120);
DrawString('Click mouse to exit.');
while not Button do
;
end.